package com.example.allplan.RecyclerAdapter;

import android.content.ContentValues;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.Activity.BianJiJiHuaActivity;
import com.example.allplan.Activity.JiHuaYeMianActivity;
import com.example.allplan.JavaBean.JiHuaBaoJavaBean;
import com.example.allplan.JavaBean.JiHuaJavaBean;
import com.example.allplan.JavaBean.JiHuaTiaoJavaBean;
import com.example.allplan.R;
import com.example.allplan.StaticFangfa.BiaoQingZhuanHuan;

import java.util.ArrayList;

public class JiHuaTiaoRecyclerAdapter extends RecyclerView.Adapter<JiHuaTiaoRecyclerAdapter.ViewHolder> {

    ArrayList<JiHuaTiaoJavaBean> mList;
    onItemClickListener mListener;
    Context mcon;
    public JiHuaTiaoRecyclerAdapter(ArrayList<JiHuaTiaoJavaBean> m, onItemClickListener mL, Context mcon){
        mListener=mL;
        mList=m;
        this.mcon=mcon;
    }
    public void setlist(ArrayList<JiHuaTiaoJavaBean> ml){
        mList=ml;
    }


    public interface onItemClickListener{
        void onClick(int pos, Context mcon);
    }
    public JiHuaTiaoRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.yi_ge_ji_hua_tiao_item_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final JiHuaTiaoRecyclerAdapter.ViewHolder holder, final int position) {
        holder.ming_cheng_textview.setText(mList.get(position).getMingcheng());
        if(mcon instanceof JiHuaYeMianActivity) {
            holder.shi_jian_textview.setText(mList.get(position).getZan_cun_zhi()+"");
        }else if(mcon instanceof BianJiJiHuaActivity){
            holder.shi_jian_textview.setText(mList.get(position).getChu_shi_zhi()+"");
        }

        holder.item_linear_view.setOnClickListener(new View.OnClickListener() {
            @Override
            synchronized public void  onClick(View v) {
                mListener.onClick(holder.getLayoutPosition(),mcon);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView ming_cheng_textview,shi_jian_textview;
        LinearLayout item_linear_view;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ming_cheng_textview=itemView.findViewById(R.id.ji_hua_tiao_ming_textview);
            shi_jian_textview=itemView.findViewById(R.id.ji_hua_tiao_shi_jian_textview);
            item_linear_view=itemView.findViewById(R.id.ji_hua_tiao_gen_view);
        }

    }
}
